#########################################################################
##
## This file is part of the SAMRAI distribution.  For full copyright 
## information, see COPYRIGHT and LICENSE. 
##
## Copyright:     (c) 1997-2019 Lawrence Livermore National Security, LLC
## Description:   makefile for linear advection performance test 
##
#########################################################################

SAMRAI        = @top_srcdir@
SRCDIR        = @srcdir@
SUBDIR        = source/test/performance/LinAdv
VPATH         = @srcdir@
OBJECT        = ../../../..
REPORT        = $(OBJECT)/report.xml
TESTLIBDIR    = $(OBJECT)/source/test/testlib
TESTLIB       = $(TESTLIBDIR)/libSAMRAI_test$(LIB_SUFFIX)

default:      main

include $(OBJECT)/config/Makefile.config

SUBDIRS = fortran

CPPFLAGS_EXTRA = 

NUM_TESTS = 2
TEST_NPROCS = @TEST_NPROCS@
QUOTE = \"

CXX_OBJS      = main.o LinAdv.o
F_OBJS      = \
	    fortran/flux3d.o fortran/grad3d.o fortran/init3d.o \
	    fortran/stable3d.o fortran/stufprobc3d.o fortran/trace3d.o \
	    fortran/trace1d3d.o fortran/fluxcorner3d.o \
	    fortran/flux2d.o fortran/grad2d.o fortran/init2d.o \
	    fortran/stable2d.o fortran/stufprobc2d.o fortran/trace2d.o \
	    fortran/trace1d2d.o

main:	$(CXX_OBJS) $(F_OBJS) $(LIBSAMRAIDEPEND) $(TESTLIB)
	(cd $(TESTLIBDIR) && $(MAKE) library) || exit 1
	for DIR in $(SUBDIRS); do if test -d $$DIR; then (cd $$DIR && $(MAKE) $@) ; fi || exit 1; done
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_OBJS) $(F_OBJS) $(TESTLIB) \
	$(LIBSAMRAI) $(LDLIBS) -o $@

# Prevents "No rule to make target" error.  Built in the rule for main.
$(TESTLIB):

fortran/flux3d.o:

fortran/grad3d.o:

fortran/init3d.o:

fortran/stable3d.o:

fortran/stufprobc3d.o:

fortran/trace3d.o:

fortran/trace1d3d.o:

fortran/fluxcorner3d.o:

fortran/flux2d.o:

fortran/grad2d.o:

fortran/init2d.o:

fortran/stable2d.o:

fortran/stufprobc2d.o:

fortran/trace2d.o:

fortran/trace1d2d.o:

testlib:
	cd $(TESTLIBDIR) && $(MAKE) library

check:	main
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"performance LinAdv\" name=$(QUOTE)domainexpansion $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./main test_inputs/domainexpansion.input | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"performance LinAdv\" name=$(QUOTE)domainexpansionb $$p procs$(QUOTE)>" >> $(REPORT); \
	  $(OBJECT)/config/serpa-run $$p ./main test_inputs/domainexpansionb.input | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	  echo "    </testcase>" >> $(REPORT); \
	done; \
	$(RM) foo

checkcompile: main

checktest:
	$(RM) makecheck.logfile
	$(MAKE) check 2>&1 | $(TEE) makecheck.logfile
	$(OBJECT)/source/test/testtools/testcount.sh $(TEST_NPROCS) $(NUM_TESTS) 0 makecheck.logfile
	$(RM) makecheck.logfile

examples:

perf:	main
	@for i in performance_inputs/*.input ; do	\
	  $(OBJECT)/config/serpa-run $(TEST_NPROCS) \
		./main $${i};	\
	done

everything:
	$(MAKE) checkcompile || exit 1
	$(MAKE) checktest
	$(MAKE) examples
	$(MAKE) perf

checkclean:
	$(CLEAN_COMMON_CHECK_FILES)
	$(RM) *.timing*

clean: checkclean
	$(CLEAN_COMMON_TEST_FILES)
	$(RM) main
	for DIR in $(SUBDIRS); do if test -d $$DIR; then (cd $$DIR && $(MAKE) $@) ; fi || exit 1; done

include $(SRCDIR)/Makefile.depend
